<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="80px"
  (onSearch)="queryResetData($event)"
  (onReset)="queryResetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-4">
  <div class="opera-wrap">
    <button
      nz-button
      nzType="primary"
      [nzLoading]="exportLoading"
      (click)="exportTable()"
    >导出</button>
  </div>

  <div class="pagination-wrap-position p-t-10">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzBordered
      [nzWidthConfig]="tbWidthConfig"
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" colspan="4">商品信息</th>
          <th nzAlign="center" colspan="8">发生信息</th>
        </tr>
        <tr>
          <th nzAlign="center">编码</th>
          <th nzAlign="center">状态</th>
          <th nzAlign="center">69码</th>
          <th nzAlign="center">名称</th>
          <th nzAlign="center">仓库</th>
          <th nzAlign="center">品质</th>
          <th nzAlign="center">发生数量</th>
          <th nzAlign="center">发生时间</th>
          <th nzAlign="center">单价</th>
          <th nzAlign="center">关联单号</th>
          <th nzAlign="center">单据类型</th>
          <th nzAlign="center">备注</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 编码 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.state === 0 ? '#909399' : ''}">
              {{ data.goodsCode || '-' }}
            </span>
          </td>
          <!-- 状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.state === 0 ? '#909399' : '#67C23A'}">
              {{ data.state === 0 ? '禁用' : '启用' }}
            </span>
          </td>
          <!-- 69码 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.state === 0 ? '#909399' : ''}">
              {{ data.code || '-' }}
            </span>
          </td>
          <!-- 名称 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.state === 0 ? '#909399' : ''}">
              {{ data.name || '-' }}
            </span>
          </td>
          <!-- 仓库 -->
          <td nzAlign="center">
            {{ filterText(warehouseOptions, data.whId) }}
          </td>
          <!-- 品质 -->
          <td nzAlign="center">
            <span>
              {{ data.quality === 0 ? '不良品' : '良品' }}
            </span>
          </td>
          <!-- 发生数量 -->
          <td nzAlign="center">
            <span [ngSwitch]="data.type">
              <!-- 入库 -->
              <p *ngSwitchCase="1">
                <span style="color: #67C23A;">
                  {{ data.number == 0 ? data.number : ('+' + data.number) }}
                </span> 
              </p>
              <!-- 出库 -->
              <p *ngSwitchCase="2">
                <span style="color: #F56C6C;">
                  {{ data.number == 0 ? data.number : ('-' + data.number) }}
                </span>
              </p>
              <!-- 调拨 -->
              <p *ngSwitchCase="3">
                <ng-container *ngIf="data.number == 0; else elseTlTemplate">
                  <span style="color: #67C23A;">0</span>
                </ng-container>
                <ng-template #elseTlTemplate>
                  <span [ngStyle]="{'color': data.remark === '调拨入库' ? '#67C23A' : (data.remark === '调拨出库' ? '#F56C6C' : '')}">
                    {{ data.remark === '调拨入库' ? ('+' + data.number) : (data.remark === '调拨出库' ? ('-' + data.number) : '-') }}
                  </span>
                </ng-template>
              </p>
              <p *ngSwitchDefault>
                -
              </p>
            </span>
          </td>
          <!-- 发生时间 -->
          <td nzAlign="center">{{ data.createTime }}</td>
          <!-- 单价 -->
          <td nzAlign="center">
            <span>
              {{ data.price | number: '1.4-4' }}
            </span>
          </td>
          <!-- 关联单号 -->
          <td nzAlign="center">
            <span
              nz-tooltip
              nzTooltipTitle="点击可复制单号"
              (click)="copyContent(data.relationNo)">
              {{ data.relationNo || '-' }}
            </span>
          </td>
          <!-- 单据类型 -->
          <td nzAlign="center">
            <span>
              {{ data.type | storeBillType: 'label' }}
            </span>
          </td>
          <!-- 备注 -->
          <td nzAlign="center">{{ data.remark || '-' }}</td>
        </tr>

        <tr
          *ngIf="tableParams?.tableData?.length"
          style="background: #fafafa; font-weight: 600;">
          <td nzAlign="center" colSpan="6">合计</td>
          <td nzAlign="center">
            <!-- put -->
            <span style="color: #67C23A;">
              {{ sumTotalData?.putSumNumber ? '+' + sumTotalData?.putSumNumber : '0' }}
            </span>

            <nz-divider nzType="vertical"></nz-divider>

            <!-- out -->
            <span style="color: #F56C6C;">
              {{ sumTotalData?.outSumNumber ? '-' + sumTotalData?.outSumNumber : '0' }}
            </span>
          </td>
          <td nzAlign="center">-</td>
          <td nzAlign="center">-</td>
          <td nzAlign="center" colSpan="3">-</td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>